/*
 * Copyright (C) 2009 M. Hautle.
 * 
 * This file is part of TrackedBean.
 * 
 * TrackedBean is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
 * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 * 
 * TrackedBean is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with TrackedBean. If not, see
 * <http://www.gnu.org/licenses/>.
 */
package ch.trackedbean.binding.guicomponents.action;

import java.awt.*;
import javax.swing.*;
import ch.trackedbean.binding.guicomponents.lists.*;

/**
 * {@link ISelectionAction} for {@link IListAdapter}s.<br>
 * Use this action if your action is dependent of an adaptable component.
 * 
 * @param <T> The type of the adapted component
 * @param <C> The content type of the adapted component
 * 
 * @author M. Hautle
 */
public abstract class AbstractListAdapterAction<T extends Component, C> extends AbstractAction implements ISelectionAction<C> {
	/** The adapter wrapping the component on which this action depends. */
	protected final IListAdapter<T, C> adapter;

	/**
	 * Default constructor.<br>
	 * Registers this action directly on the passed adapter.
	 * 
	 * @param adapter The adapter
	 */
	public AbstractListAdapterAction(IListAdapter<T, C> adapter) {
		this.adapter = adapter;
		adapter.addAction(this);
	}

	/**
	 * Default constructor.<br>
	 * Registers this action directly on the passed adapter.
	 * 
	 * @param adapter The adapter
	 * @param name The action name
	 * @param icon The action icon
	 */
	public AbstractListAdapterAction(IListAdapter<T, C> adapter, String name, Icon icon) {
		super(name, icon);
		this.adapter = adapter;
		adapter.addAction(this);
	}

	/**
	 * Default constructor.<br>
	 * Registers this action directly on the passed adapter.
	 * 
	 * @param adapter The adapter
	 * @param name The action name
	 */
	public AbstractListAdapterAction(IListAdapter<T, C> adapter, String name) {
		super(name);
		this.adapter = adapter;
		adapter.addAction(this);
	}

	/**
	 * Returns the adapter wrapping the component on which this action depends.<br>
	 * You may use the adapter to retrive the model of the wrapped component (if there is one available).
	 * 
	 * @return Returns the adapter.
	 */
	public IListAdapter<T, C> getAdapter() {
		return adapter;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getActionID() {
		return getClass().getName();
	}
}
